package com.zhiyou100.crm.servlet.message;

import com.zhiyou100.crm.service.MessageService;
import com.zhiyou100.crm.service.impl.MessageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/message/delete")
public class DeleteServlet extends HttpServlet {private static final long serialVersionUID = 1L;
    MessageService messageService=new MessageServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");
        String field = request.getParameter("searchField");
        int messageId = Integer.parseInt(request.getParameter("id"));
        String side = request.getParameter("side");
        String forever = request.getParameter("forever");
        int mid = messageService.delete(messageId);
        // 重定向到请求来源页，注意向学生讲一下Referer请求头
        response.sendRedirect(request.getContextPath()+"/message/listRemove");
    }
}
